<template>
  <a-modal
    title="物资合同评审选择"
    :visible="visible"
    class="pub-middle-dialog"
    @ok="handleOk"
    @cancel="visible=false"
  >
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <!--eslint-disable-->
    <b-table
      ref="table"
      :columns="columns"
      :request="loadData"
      :selectConfig="{use: true, type: 'radio',rowKey: 'id' }"
      @row-click="(e,row) => this.selectRow = row"
      row-key="id"
    >
      <span slot="num" slot-scope="text, record, index">{{ index + 1 }}</span>
    </b-table>
  </a-modal>
</template>
<script>
import { contractReviewList } from '@/api/material/contract/review'

export default {
  name: 'a' + Date.now(),
  props: {
    otherParams: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data: function() {
    return {
      queryParam: {},
      visible: false,
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'num' }
        },
        {
          title: '合同编号',
          dataIndex: 'code'
        },
        {
          title: '合同名称',
          dataIndex: 'name'
        }
      ],
      searchArr: [
        {
          name: '合同编号',
          value: 'code',
          type: 'input'
        }
      ],
      selectRow: null,
      loadData: params => {
        return contractReviewList(Object.assign(params, this.queryParam, {
          auditStatus: 'PAST',
          typeId: 2, ...this.otherParams
        }))
      }
    }
  },
  methods: {
    open: function() {
      this.visible = true
      this.search()
    },
    handleOk() {
      if (this.selectRow === null) return this.$noticeWarning('请选择数据')
      this.visible = false
      this.$emit('ok', this.selectRow)
    },
    search(val) {
      this.queryParam = val
      this.$refs.table && this.$refs.table.getData(null, true)
    }
  }
}
</script>
